﻿using log4net;
using System;
using System.Reflection;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
namespace AnyOffice.general.system.workflow.flow_sign
{
    public  partial  class sign_new : ModulePage
    {      
       
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                int num = -1;
                FlowSignDao dao = new FlowSignDao();
                FlowSignData data = new FlowSignData();
                data.SignNo = Convert.ToInt32(this.txtSignNo.Text);
                data.SignName = this.txtSignName.Text;
                if (this.txtSignMemo.Text != string.Empty)
                {
                    data.SignMemo = this.txtSignMemo.Text;
                }
                num = dao.Insert(base.Conn, data);
                if ((num != -1) && (this.fileSign.PostedFile.ContentLength > 0))
                {
                    try
                    {
                        Upload upload = new Upload();
                        upload.OverwriteFile = true;
                        upload.DestinationPath = Server.MapPath("/module/oc/");
                        upload.DestinationFileName = "sign_" + num.ToString() + ".esp";
                        upload.GetFile(this.fileSign.PostedFile);
                        upload.DoUpload();
                        this.litMessage.Text = base.ShowPrompt("新建电子印章成功！", "index.aspx");
                        return;
                    }
                    catch (Exception exception)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("", exception);
                        }
                        dao.Delete(base.Conn, num);
                        this.litMessage.Text = base.ShowPrompt("新建电子印章失败！", "index.aspx");
                    }
                }
                dao.Delete(base.Conn, num);
                this.litMessage.Text = base.ShowPrompt("新建电子印章失败！", "index.aspx");
            }
        }
        
    }
}

